package org.example;

import java.util.Scanner;

public class test11 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str;
        while (true) {
            System.out.println("请输入一个字符串：");
            str = sc.next();
            boolean flag = Cherkstr(str);
            if (flag) {
                break;
            } else {
                System.out.println("输入的不和规矩，请重新输入");
                continue;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            int number = c - '0';
            String str2 = ChangeRoman(number);
            sb.append(str2+" ");
        }
        System.out.println(sb);
    }

   public static boolean Cherkstr(String str) {
        if(str.length()>9) {
            return false;
        }
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if(c<'0'||c>'9') {
                return false;
            }
        }
       return true;
   }

    public static String ChangeRoman(int number) {
        //以空字符开头，方便索引对应
        String []arr = {"","I","II","III","IV","V","VI","VII","VIII","IX"};
        return arr[number];
    }
}

